import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/",
    redirect: "/login",
    component: () => import("@/views/login/index"),
  },
  {
    path: "/login",
    // redirect: "/dashboard",
    component: () => import("@/views/login/index"),
  },
  {
    path: "/login2",
    name: "Login2",
    component: () => import("@/views/login/Login2.vue"),
  },
  {
    path: "/register",
    name: "Register",
    component: () => import("@/views/login/Register.vue"),
  },
  {
    path: "/password",
    name: "Password",
    component: () => import("@/views/login/Password.vue"),
  },
  {
    path: "/retrieve",
    name: "Retrieve",
    component: () => import("@/views/login/Retrieve.vue"),
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/dashboard",
    component: Layout,
    // redirect: "Dashboard",
    children: [
      {
        path: "dash",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { 
          title: "标准管理", 
          icon: "dashboard" 
        },
      },
    ],
  },

  /*  {
    path: "dashboard",
    name: "Dashboard",
    component: () => import("@/views/dashboard/index"),
    meta: { title: "首页", icon: "dashboard" },
  },*/

  /*  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/Login1.vue')
  },*/

  {
    path: "/project-manage",
    component: Layout,
    redirect: "/project-manage/p/index",
    name: "标准管理",
    hidden: true,
    children: [
      
      {
        path: "/project-manage/project/:param",
        name: "project-manage",
        // redirect: '/project-manage/p/p1',

        component: () => import("@/views/project-manage/p/project/index.vue"),
        meta: { title: "项目管理", icon: "dashboard" },
       
      },

      {
        path: "/moudle_select/:param",
        name: "moudle_select",
        component: () => import("@/views/project-manage/p/moudle_select/index.vue"),
        meta: { title: "模块选择" },
        hidden: true,
      },
      {
        path: "equip_manage/:param",
        name: "equip_manage",
        component: () => import("@/views/project-manage/p/equip_manage/index.vue"),
        meta: { title: "设备管理" },
        hidden: true,
      },
      {
        path: "equip_plan/:id",
        name: "equip_plan",
        component: () => import("@/views/project-manage/p/equip_plan/index.vue"),
        meta: { title: "设备方案" },
        hidden: true,
      },
      {
        path: "add_equip",
        name: "add_equip",
        component: () => import("@/views/project-manage/p/add_equip/index.vue"),
        meta: { title: "添加方案" },
        hidden: true,
      },
      {
        path: "way_manage",
        name: "way_manage",
        component: () => import("@/views/project-manage/p/way_manage/index"),
        meta: { title: "方案管理" },
        hidden: true,
      },
      {
        path: "sample_check/:param",
        name: "sample_check",
        component: () => import("@/views/project-manage/p/sample_check/index"),
        meta: { title: "样品查看" },
        hidden: true,
      },
      {
        path: "people",
        name: "people",
        component: () => import("@/views/people/people.vue"),
        meta: { title: "人员管理" },
        hidden: true,
      },
      {
        path: "train_manage",
        name: "train_manage",
        component: () => import("@/views/people/train_manage/train.vue"),
        meta: { title: "培训管理" },
        hidden: true,
        props: true,
      },
      {
        path: "audit_list",
        name: "audit_list",
        component: () => import("@/views/people/train_manage/audit_list.vue"),
        meta: { title: "授权列表" },
        hidden: true,
        props: true,
      },
      {
        path: "audit",
        name: "audit",
        component: () => import("@/views/people/train_manage/audit.vue"),
        meta: { title: "考核授权" },
        hidden: true,
        props: true,
      }
    ],
  },


  {
    path: "/message-manage",
    component: Layout,
    meta: { title: "留言管理", icon: "form" },
    children: [
      {
        path: "message",
        name: "message",
        component: () => import("@/views/message-manage/message"),
        meta: { title: "留言管理", icon: "form" },
      },
      {
        path: "/reply/:backID",
        name: "reply",
        component: () => import("@/views/message-manage/reply"),
        meta: { title: "留言回复", icon: "form" },
        hidden: true,
      },
      {
        path: "/check_reply/:backID",
        name: "check_reply",
        component: () => import("@/views/message-manage/check_reply"),
        meta: { title: "留言查看", icon: "form" },
        hidden: true,
      },
    ],
  },

  {
    path: "/list-manage",
    component: Layout,
    redirect: "/list-manage/sample-manage",
    name: "list-manage",
    meta: {
      title: "清单管理",
      icon: "nested",
    },
    children: [
      {
        path: "sample-manage",
        name: "sample-manage",
        component: () => import("@/views/list-manage/sample-manage"),
        meta: { title: "样品发放清单", icon: "nested" },
      },
      {
        path: "device-manage",
        component: () => import("@/views/list-manage/device-manage.vue"),
        name: "device-manage",
        meta: { title: "设备计划采购清单", icon: "nested" },
      },
    ],
  },

  {
    path: "/comparison-manage/index",
    component: Layout,
    children: [
      {
        path: "/comparison-manage/index",
        component: () => import("@/views/comparison-manage/index.vue"),
        name: "comparison-manage",
        meta: { title: "比对方案", icon: "nested" },
      },
    ],
  },

  {
    path: "/people",
    component: Layout,
    redirect: "people",
    name: "人员界面",
    hidden: true,
    // meta: {
    //   title: "人员界面",
    //   icon: "nested",
    // },
    children: [
      {
        path: "people/:projectId",
        name: "people",
        component: () => import("@/views/people/people.vue"),
        meta: { title: "人员界面", icon: "nested" },
        props: true
      },

      {
        path: "train/:projectId",
        component: () => import("@/views/people/train_manage/train.vue"),
        name: "train",
        meta: { title: "培训管理" },
        props: true
      },
      {
        path: "leave-words",
        component: () => import("@/views/people/train_manage/leave-words.vue"),
        name: "leave-words",
        meta: { title: "留言管理" },
      },

      {
        path: "audit_list/:projectId",
        component: () => import("@/views/people/train_manage/audit_list.vue"),
        name: "audit_list",
        meta: { title: "授权列表" },
        props: true
      },

      {
        path: 'audit/:projectId',
        component: () => import('@/views/people/train_manage/audit.vue'),
        name: 'audit',
        meta: { title: '授权审核' },
        props: route => ({
          id: route.query.id,
          pass: route.query.pass,
          projectId: route.params.projectId,
          uId: route.query.uId
        })
      },


      {
        path: "certificate",
        component: () => import("@/views/people/train_manage/certificate.vue"),
        name: "certificate1",
        meta: { title: "证书界面" },
      },
    ],
  },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
